import { Body, Controller, Get, Post, Query, Req } from '@nestjs/common';
import {
  ApiBearerAuth,
  ApiOperation,
  ApiQuery,
  ApiTags,
} from '@nestjs/swagger';
import { ResultScoreDto } from './dto/add-study-match-score.dto';
import { InvitationCodeDto } from './dto/invitation-code.dto';
import { StudyMatchNeedDto } from './dto/study-match-need.dto';
import { UserMessageDto } from './dto/user-message.dto';
import { StudyMatchService } from './study-match.service';

@ApiTags('学习匹配管理')
@Controller('study-match')
export class StudyMatchController {
  constructor(private readonly studyMatchService: StudyMatchService) {}

  @ApiOperation({
    summary: '提交匹配的个人资料',
  })
  @ApiBearerAuth()
  @Post('/submitUserMessage')
  submitUserMessage(@Body() userMessage: UserMessageDto, @Req() req) {
    userMessage.userId = req.user.id;
    return this.studyMatchService.submitUserMessage(userMessage);
  }

  @ApiOperation({
    summary: '获取提交匹配的个人资料',
  })
  @ApiBearerAuth()
  @Get('/getUserMessage')
  getUserMessage(@Req() req) {
    return this.studyMatchService.getUserMessage(Number(req.user.id));
  }

  @ApiOperation({
    summary: '提交想要匹配的需求-报名',
  })
  @ApiBearerAuth()
  @Post('/submitStudyMatchNeed')
  submitStudyMatchNeed(
    @Req() req,
    @Body() studyMatchNeedDto: StudyMatchNeedDto,
  ) {
    studyMatchNeedDto.userId = req.user.id;
    return this.studyMatchService.submitStudyMatchNeed(studyMatchNeedDto);
  }

  @ApiOperation({
    summary: '获取提交想要匹配的需求',
  })
  @ApiBearerAuth()
  @Get('/getStudyMatchNeed')
  getStudyMatchNeed(@Req() req) {
    return this.studyMatchService.getStudyMatchNeed(Number(req.user.id));
  }

  @ApiOperation({
    summary: '取消报名',
  })
  @ApiBearerAuth()
  @Post('/cancelStudyMatch')
  cancelStudyMatch(@Req() req) {
    return this.studyMatchService.cancelStudyMatch(Number(req.user.id));
  }

  @ApiOperation({
    summary: '查询匹配状态',
  })
  @ApiBearerAuth()
  @Get('/getStudyMatchStatus')
  getStudyMatchStatus(@Req() req) {
    return this.studyMatchService.getStudyMatchStatus(Number(req.user.id));
  }

  @ApiOperation({
    summary: '生成邀请码',
  })
  @ApiBearerAuth()
  @Post('/createInvitationCode')
  createInvitationCode(@Req() req) {
    const userId = req.user.id;
    return this.studyMatchService.createInvitationCode(userId);
  }

  @ApiOperation({
    summary: '根据邀请码匹配用户',
  })
  @ApiBearerAuth()
  @Post('/matchUserByInvitationCode')
  matchUserByInvitationCode(
    @Req() req,
    @Body() invitationCodeDto: InvitationCodeDto,
  ) {
    invitationCodeDto.userId = req.user.id;
    return this.studyMatchService.matchUserByInvitationCode(invitationCodeDto);
  }

  @ApiOperation({
    summary: '增加积分',
  })
  @ApiBearerAuth()
  @Post('/addStudyMatchScore')
  addStudyMatchScore(@Req() req, @Body() resultScoreDto: ResultScoreDto) {
    return this.studyMatchService.addStudyMatchScore(
      Number(req.user.id),
      Number(resultScoreDto.num),
      Number(resultScoreDto.type),
    );
  }

  @ApiOperation({
    summary: '获取任务列表状态',
  })
  @ApiQuery({
    name: 'matchId',
    description: '匹配id',
    example: 0,
  })
  @ApiBearerAuth()
  @Get('/getTaskList')
  getTaskList(@Query('matchId') matchId: number) {
    return this.studyMatchService.getTaskList(Number(matchId));
  }
}
